package be.kuleuven.peno3.mobiletoledo.Data.Client;

import java.io.IOException;
import java.util.Calendar;

import com.google.gson.Gson;

public abstract class MenuClient extends Client{
	
	public static String[] getMenu(String restaurant, Calendar dag) {
		try {  
			String url ="restaurant="+restaurant+"&dag="+toSQLStringDate(dag);
			url=host+"/MenuHandler/getMenu?"+url;
			String json = stringOfUrl(url);
			
			Menu[] menu =new Gson().fromJson(json.toString(), Menu[].class);
			
			String[] result = new String[] {menu[0].voorgerecht, menu[0].hoofdgerecht, menu[0].nagerecht};
			return result;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		} catch (ArrayIndexOutOfBoundsException ex) {
			ex.printStackTrace();
			String[] result = new String[] {"none"};
			return result;
		}
	}
	
	private static String toSQLStringDate(Calendar cal){
		String year=""+cal.get(Calendar.YEAR);
		String month=""+(cal.get(Calendar.MONTH)+1);
		String day= ""+cal.get(Calendar.DAY_OF_MONTH);
		return year+"-"+month+"-"+day;
	}
	
	private static class Menu{public String hoofdgerecht, voorgerecht, nagerecht;}
}
